﻿using ZhuXingFamilys.Database;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using MaterialDesignThemes.Wpf;
using MaterialDesignColors;

namespace ZhuXingFamilys.User
{
    /// <summary>
    /// RegisterWindow.xaml 的交互逻辑
    /// </summary>
    public partial class RegisterWindow : Window
    {
        public RegisterWindow()
        {
            ColorZoneAssist.SetMode(new GroupBox(), ColorZoneMode.Light);
            Hue hue = new Hue("name", System.Windows.Media.Color.FromArgb(1, 2, 3, 4), System.Windows.Media.Color.FromArgb(1, 5, 6, 7));
            WindowStartupLocation = WindowStartupLocation.CenterScreen;
            InitializeComponent();
        }
        public static Hashtable userall;
        private void MoveWindow_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            DragMove();
        }

        private void ReClose_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
        public static string UserName;
        public static string UserPassword;

        private void Register_Button(object sender, RoutedEventArgs e)
        {
            string u = Re_Account.Text.ToString();
            string p = Re_Password.Password.ToString();
            string rp = Re_PasswordAgain.Password.ToString();
            //ExcelSave excel = new ExcelSave();
            SqlserverDatabase SqlServer = new SqlserverDatabase();


            if (String.IsNullOrEmpty(u))
            {
                MessageBox.Show("请输入用户名");
                return;
            }
            if (String.IsNullOrEmpty(p))
            {
                MessageBox.Show("请输入密码");
                return;
            }
            if (String.IsNullOrEmpty(rp))
            {
                MessageBox.Show("请确认第二次数据密码正确");
                return;
            }
            if (!p.Equals(rp))
            {
                MessageBox.Show("两次输入密码不同");
                return;
            }

            userall = SqlServer.sqlserver_read();
            //userall = excel.readExcel();  //读取excel数据
            if (userall == null)
            {
                userall = new Hashtable();
                userall.Add(u, p);
            }
            else
            {
                bool isexist = userall.ContainsKey(u);  //判断用户是否存在
                if (isexist)
                {
                    MessageBox.Show("用户存在");
                    return;
                }
                else
                {
                    userall.Add(u, p);
                    Console.WriteLine(userall.Count);
                }
            }
           
            //Application.Current.Properties["users"] = userall;   //类似于Session的功能,用户登录后，可以将用户的信息保存在Properties中。
            //excel.InsertExcel(u, p);
            SqlServer.Sqlserver_insert(u, p);
            UserLogin form1 = new UserLogin(UserName, UserPassword);
            MessageBox.Show("注册成功!");
            this.Close();



        }
    }
}
